package com.scalar.chiptrack.commons;

import org.apache.poi.ss.usermodel.CellStyle;
import com.scalar.chiptrack.utils.ExcelUtils;


/**
 * User: ssujan
 * Date: May 6, 2010
 * Time: 7:43:27 PM
 */
public class ExcelColumnProperties {
    private int cellStyle;
    private int totalcellStyle;
    private int colWidth;
    private boolean isShowTotal = false;
    private boolean isGroupBy = false;
    private boolean isShowSubTotal = false;
    private int priority;
    private String colName;
    private int colIdx = -1;
	private boolean formula = false;

    public static final int CELL_STYLE_TITLE = 1;
    public static final int CELL_STYLE_HEADER = 2;
    public static final int CELL_STYLE_TEXT = 3;
    public static final int CELL_STYLE_NUMBER = 4;
    public static final int CELL_STYLE_DATE = 5;
    public static final int CELL_STYLE_FLOAT = 6;
    public static final int CELL_STYLE_FLOAT_PER = 7;
    public static final int CELL_STYLE_NUMERIC = 8;
    public static final int CELL_STYLE_CURRENCY_$ = 9;
    public static final int CELL_STYLE_CURRENCY_FORMATTED_$ = 10;
    public static final int CELL_STYLE_CURRENCY_$_TOTAL = 11;
    public static final int CELL_STYLE_NUMBER_TOTAL = 12;

    public ExcelColumnProperties(String colName) {
        setColName(colName);
    }

    public ExcelColumnProperties(int colIdx) {
        setColIdx(colIdx);
    }

	public ExcelColumnProperties(String colName, int cellStyle, boolean formula) {
        setColName(colName);
		setCellStyle(cellStyle);
		setFormula(formula);
    }

    /**
     *
     * @param excelUtils Utility class which is used to create cell styles in the workbook and the same style is returned.
     * @return CellStyle object to be applied for this column.
     */
    public CellStyle getCellStyle(ExcelUtils excelUtils) {
        switch(cellStyle) {
            case CELL_STYLE_TITLE:
                return excelUtils.CELL_STYLE_TITLE;
            case CELL_STYLE_HEADER:
                return excelUtils.CELL_STYLE_HEADER;
            case CELL_STYLE_TEXT:
                return excelUtils.CELL_STYLE_TEXT;
            case CELL_STYLE_NUMBER:
                return excelUtils.CELL_STYLE_NUMBER;
            case CELL_STYLE_DATE:
                return excelUtils.CELL_STYLE_DATE;
            case CELL_STYLE_FLOAT:
                return excelUtils.CELL_STYLE_FLOAT;
            case CELL_STYLE_FLOAT_PER:
                return excelUtils.CELL_STYLE_FLOAT_PER;
            case CELL_STYLE_NUMERIC:
                return excelUtils.CELL_STYLE_NUMERIC;
            case CELL_STYLE_CURRENCY_$:
                return excelUtils.CELL_STYLE_CURRENCY_$;
			case CELL_STYLE_CURRENCY_FORMATTED_$:
				return excelUtils.CELL_STYLE_CURRENCY_FORMATTED_$;
            default:
                return null;
        }
    }

    /**
     *
     * @param cellStyle style to be applied for this column.
     * @see #CELL_STYLE_TITLE
     * @see #CELL_STYLE_HEADER
     * @see #CELL_STYLE_TEXT
     */
    public void setCellStyle(int cellStyle) {
        this.cellStyle = cellStyle;
    }

    public CellStyle getTotalcellStyle(ExcelUtils excelUtils) {
        switch(totalcellStyle) {
            case CELL_STYLE_CURRENCY_$_TOTAL:
				return excelUtils.CELL_STYLE_CURRENCY_$_TOTAL;
             case CELL_STYLE_NUMBER_TOTAL:
				return excelUtils.CELL_STYLE_NUMBER_TOTAL;
            default:
                return null;
        }
    }

    public void setTotalcellStyle(int totalcellStyle) {
        this.totalcellStyle = totalcellStyle;
    }

    /**
     *
     * @return the width to be applied for this column.
     */
    public int getColWidth() {
        return colWidth;
    }

    /**
     * Set the width (in units of 1/256th of a character width)
     * <br>The maximum column width for an individual cell is 255 characters.
     * <br>This value represents the number of characters that can be displayed in a cell that is formatted with the standard font.
     *
     * <br>Eg: If you want to set the column width to 20 characters then set width to 10*256 i.e 2560.
     * @param colWidth the width in units of 1/256th of a character width
     */
    public void setColWidth(int colWidth) {
        this.colWidth = colWidth;
    }

    /**
     *
     * @return true if total is shown for this column otherwise false.
     */
    public boolean isShowTotal() {
        return isShowTotal;
    }

    /**
     * whether to show total or not for this column.
     * @param showTotal true = show total. false = do not show total.
     */
    public void setShowTotal(boolean showTotal) {
        isShowTotal = showTotal;
    }

    /**
     *
     * @return  the Column name for which the properties to be applied.
     * <br> If colIdx is set then the null is returned.
     */
    public String getColName() {
        return colName;
    }

    /**
     * To set the column name for which the properties to be applied.
     * <br>Set either column name or col idx.
     * @param colName
     */
    public void setColName(String colName) {
        this.colIdx = -1;
        this.colName = colName;
    }

    /**
     *
     * @return the column index(0-based) for which the properties to be applied.
     * <br> -1 if col Name is specified.
     */
    public int getColIdx() {
        return colIdx;
    }

    /**
     * To set the column Idx(0-based) for which the properties to be applied.
     * <br>Set either column name or col idx.
     * @param colIdx
     */
    public void setColIdx(int colIdx) {
        this.colName = null;
        this.colIdx = colIdx;
    }

	public boolean isFormula() {
		return formula;
	}

	public void setFormula(boolean formula) {
		this.formula = formula;
	}

    public boolean isGroupBy() {
        return isGroupBy;
    }

    public void setGroupBy(boolean isgroupBy) {
        this.isGroupBy = isgroupBy;
    }

    public boolean isShowSubTotal() {
        return isShowSubTotal;
    }

    public void setShowSubTotal(boolean showSubTotal) {
        isShowSubTotal = showSubTotal;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }
}
